class ComponentNode extends MyNode{
    constructor($state='new',...obj){
        super('Component',$state,{
            name:"部件名称"
        },...obj);
    }

    getTypeName(){
        return "测点位置";
    }

    getTemplate(edge,g){
        // let cps = ComponentNode.components
        //     .filter(nd=>{
        //         for (let eg of $scope.graph.edges){
        //             if(eg.from==edge.from&&eg.to==nd.id)
        //                 return false;
        //         }
        //         return true;
        //     });
        // let index = g.getLinkIndex(edge.id);
        return `
 <div class="form-group">
    <label class="col-sm-2 control-label">测点位置</label>
     <div class="col-sm-10">
    <select class="form-control"
    data-ng-options="component.name for component in components"
    data-ng-model="component_ref" 
    data-ng-change="graph.resetLink(${edge},component_ref,reloadGraph)"
    data-ng-init="component_ref=graph.getNodeFromList('${this.id}',components)"
    ></select>
 </div>
 </div>
 
 <div class="form-group">
 <label class="col-sm-2 control-label">操作</label>
 <p class="col-sm-10 form-control-static">
 <a class="btn" href="javascript:;" ng-click="removeEdge(${edge})">删除当前节点</a>
</p>
</div>
`;
    }

    static loadComponents(){
        let session = neo4jService.getSession();
        let resultPromise = session.run(`MATCH (n:Component) RETURN n`);
        resultPromise.then(result => {
            session.close();
            ComponentNode.components = result.records
                .map((record) => record.get(0))
                .map(node => MyNode.fromNeo4jNode(node));
            for (let fn of ComponentNode.loadComponents.callbacks){
                fn(ComponentNode.components);
            }
        });
    }

    static loadComponentsFrom(superId,...callbacks){
        let session = neo4jService.getSession();
        let resultPromise = session.run(`start s=node(${superId}) MATCH (s)-[*]->(n:Component) RETURN n`);
        resultPromise.then(result => {
            session.close();
            let components = result.records
                .map((record) => record.get(0))
                .map(node => MyNode.fromNeo4jNode(node));
            for (let fn of callbacks){
                fn(components);
            }
        });
    }
}
ComponentNode.components=[];
// ComponentNode.loadComponents();
ComponentNode.loadComponents.callbacks=[];